<script>

 
top.$('preFrames').setStyle('display', 'block');
top.$('preFrames').setStyle('top', '10px');
//top.$('preFrames').setStyle('left', screen.width/20  );

</script> 
<!--- loop through the selected storage --->
<cfloop list="#path#" index="p">
<!--- get file info from db --->
<cfquery  datasource="101tf2" name="getLastest">
 select  * from scan where 
 (name like '%.ogm'  
 or  name like '%.avi' 
 or name like '%.flv'
 or name like '%.mpg'
 or name like '%.wmv'
 or name like '%.mp4'
 or name like '%.mpeg'
 ) and dir not like '%Adobe Premiere Pro Preview Files%' 
 and
 dir like '#replace(urldecode(p),"\","\\\","ALL")#%'
 order by date desc  
 </cfquery>
<!--- reset progress --->
<cfset lastProg=-1>
<!--- js info out --->
<script>
	top.document.getElementById("txt").innerHTML='Screen shot job started. Checking for new video files.';
</script>
<cfflush>
<!--- loop through the query --->
<cfoutput query="getLastest">
    <cfprocessingdirective suppressWhiteSpace="true"> 
		<!--- calc progress --->
        <cfset prog=(currentrow*100) / recordcount >
        <!--- only output progress by 1% --->
        <cfif lastProg neq #Round(prog)#>
        <script>
            top.document.getElementById("progressBar").style.width='#Round(prog)*progressWidth#px';
            top.document.getElementById("per").innerHTML='#Round(prog)#% #currentrow# of #recordcount#';
        </script>
        <cfflush>
        </cfif> 
    </cfprocessingdirective>
    <!--- check if there are thumbnails created --->
    <cfdirectory action="list"  directory="#VideoThumbPath#" name="chkscan" recurse="false" filter="#id#-1.jpg" />
    <cfif not chkscan.recordcount>
    	<!--- set the start time of the thumbnails based on the size --->
        <cfif GetFileInfo('#replace(dir,'\','\\','ALL')#\\#name#').size gt 302400>
			<cfset StartTime=60> 
        <cfelseif GetFileInfo('#replace(dir,'\','\\','ALL')#\\#name#').size gt 30240>
            <cfset StartTime=20>  
        <cfelse>
            <cfset StartTime=1.5> 
        </cfif>
           <!--- display the file name --->
             <script>
                top.document.getElementById("txt").innerHTML='Adding new Screenshot: #name#';
            </script> 
    	<!--- new thumbnails ---> 
        
        	<!--- loop through the number of thumbnails --->
            <cfloop from=1 to=#NumberOfVideoThumbNails# index="i">
            	<cftry>
                    <cfexecute 
                    name='#replace(ExpandPath("/"),"\","/","ALL")#ffmpeg/ffmpeg.exe'  arguments='-y -itsoffset -#(i*2)+StartTime#  -i "#replace(dir,'\','\\','ALL')#\\#name#" -vcodec mjpeg -vframes 1 -an 
                    -f rawvideo #replace(VideoThumbPath,'\','\\','ALL')##id#-#i#.jpg' outputFile = "C:/output.txt"
                      ></cfexecute>
                <cfcatch></cfcatch>
              	</cftry>
              <!--- make sure that the thumbnail file is not 0 byte --->
            <cfif FileExists('#replace(VideoThumbPath,'\','\\','ALL')##id#-#i#.jpg') and GetFileInfo('#replace(VideoThumbPath,'\','\\','ALL')##id#-#i#.jpg').size eq 0>
            	<!--- we dont need 0 byte file --->
            	<cffile action="delete" file="#replace(VideoThumbPath,'\','\\','ALL')##id#-#i#.jpg">
            <cfelse>
            	<!--- show the thumbnail --->
				<script>
                    top.document.getElementById("snap#i#").src='showShotProgress.cfm?scene=#id#-#i#.jpg';
                </script>
			</cfif>	
            <cfflush>                            
            </cfloop>
           
       
    <cfelse>
    <!--- @@@@@@@@@@@@@@@@@@@@@@@@@@ else means at least id-1.jpg exists @@@@@@@@@@@@@@@@@@@@@@@@  --->
    <!--- @@@@@@@@@@@@@@@@@@@@@@@@@@ else means at least id-1.jpg exists @@@@@@@@@@@@@@@@@@@@@@@@  --->
    <!--- @@@@@@@@@@@@@@@@@@@@@@@@@@ else means at least id-1.jpg exists @@@@@@@@@@@@@@@@@@@@@@@@  --->
    <!--- @@@@@@@@@@@@@@@@@@@@@@@@@@ else means at least id-1.jpg exists @@@@@@@@@@@@@@@@@@@@@@@@  --->
    <script>
        top.document.getElementById("txt").innerHTML='Screenshot Exists for #name#';
    </script>
            <cfif isdefined('fixScene')> 
             <!--- if fix scene was selected try to create other thumbnails that does not exists --->
                   	<cfloop from=1 to=#NumberOfVideoThumbNails# index="i">
                   	<cfdirectory action="list" name="ch" directory="#VideoThumbPath#" filter="#id#-#i#.jpg" />
                    	<!---  --->
						<cfif not ch.recordcount>

                            <cfif GetFileInfo('#replace(dir,'\','\\','ALL')#\\#name#').size gt 302400>
                                <cfset StartTime=60> 
                            <cfelseif GetFileInfo('#replace(dir,'\','\\','ALL')#\\#name#').size gt 30240>
                                <cfset StartTime=20>  
                            <cfelse>
                                <cfset StartTime=1.5> 
                            </cfif>
                            <cfif FileExists('#replace(VideoThumbPath,'\','\\','ALL')##id#-#i#.jpg') and  GetFileInfo('#replace(VideoThumbPath,'\','\\','ALL')##id#-#i#.jpg').size eq 0>
                            	<cffile action="delete" file="#replace(VideoThumbPath,'\','\\','ALL')##id#-#i#.jpg">
                                    <script>
                                            top.document.getElementById("txt").innerHTML='Can not add scene #i#: #name#';
                                     </script>
                            <cfelse>
                                     <script>
                                            top.document.getElementById("txt").innerHTML='Adding new scene #i#: #name#';
                                     </script>
                            </cfif>
                         
                            
                            <cftry>
                            <cfexecute 
                            name='#replace(ExpandPath("/"),"\","/","ALL")#ffmpeg/ffmpeg.exe'  arguments='-y -itsoffset -#(i*2)+StartTime#  -i "#replace(dir,'\','\\','ALL')#\\#name#" -vcodec mjpeg -vframes 1 -an 
                            -f rawvideo #replace(VideoThumbPath,'\','\\','ALL')##id#-#i#.jpg' outputFile = "C:/output.txt"
                              ></cfexecute>
                                <cfcatch>
                              </cfcatch>
                              </cftry>
                            <script>
                                top.document.getElementById("snap#i#").src='showShotProgress.cfm?scene=#id#-#i#.jpg';
                            </script>	
                            <cfflush>
                        </cfif> 
                    </cfloop>
                    <cfflush>
                
            </cfif> 
            <!--- end fix scene --->  
    </cfif>
    <!--- not sure if this is the right place (will remove it later) --->
    <cfif isdefined('ShowScene')>
         <cfloop from=1 to=#NumberOfVideoThumbNails# index="i">
			 <script>
                top.document.getElementById("snap#i#").src='showShotProgress.cfm?scene=#id#-#i#.jpg';
            </script>	
         </cfloop>
        <script>
            top.document.getElementById("txt").innerHTML='Showing Existing Screenshot: #name#';
         </script>
        <cfflush>
    </cfif>
<cfset lastProg=#Round(prog)#> 
</cfoutput>
</cfloop>
<!--- Done --->
<script>
	top.document.getElementById("txt").innerHTML='Screen shot job completed.';
</script>